<?
if ($argc <= 1) {
        print("Please provide the input filename as a command-line argument:\n");
        print("\tphp -f parser.php <input_file>\n");
        return;
} else {
        $input_file = $argv[1];
}

file_exists($input_file) or die('Could not find file ' . $input_file);
if (!($fp = fopen($input_file, "r"))) {
    die("could not open input input");
}
while ($data = fgets($fp)) {
	$data = rtrim ($data);
	$a_data = explode ("\t", $data);
	if ((count ($a_data) === 7) and (strpos($data, '#') !== 0)) {
		//echo $data . PHP_EOL;
		$latitude = DegMinSecMsec_to_DEC($a_data[0]);
		$longitude = DegMinSecMsec_to_DEC($a_data[1]);
		$ssid = $a_data[2];
			$ssid = str_replace ('( ' , '', $ssid);
			$ssid = str_replace (' )' , '', $ssid);
		$bssid = $a_data[4];
			$bssid = str_replace ('( ' , '', $bssid);
			$bssid = str_replace (' )' , '', $bssid);
		if (!empty($ssid)) {
			//echo $latitude . "\t" . $longitude . "\t" . $ssid . "\t" . $bssid . PHP_EOL;
			$coor[$latitude . '-' . $longitude]['latitude']=$latitude;
			$coor[$latitude . '-' . $longitude]['longitude']=$longitude;
			//echo "new google.maps.LatLng($latitude, $longitude)" . PHP_EOL;
		}
	}
}
foreach ($coor as $one_coor) {
	echo "new google.maps.LatLng({$one_coor['latitude']}, {$one_coor['longitude']})," . PHP_EOL;
}
  // print_r ($goods);
function DegMinSecMsec_to_DEC ($input) {
	$input_a = explode (' ', $input);
	$input = $input_a[1];
	$input_a = explode ('.', $input);
	if (count ($input_a) !== 2) {
		return false;
	}
	$deg = $input_a[0];
	$min = substr($input_a[1], 0, 2);
	$sec = substr($input_a[1], 2, 2);
	$msec = substr($input_a[1], 4);
	return $deg+((($min*60)+($sec+$msec*0.001))/3600);
}
//echo DegMinSecMsec_to_DEC('N 55.413039');


    
 


?>